package com.wxb.qd.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.wxb.qd.common.ErrorCode;
import com.wxb.qd.entity.Announcement;
import com.wxb.qd.exception.BusinessException;
import com.wxb.qd.service.AnnouncementService;
import com.wxb.qd.mapper.AnnouncementMapper;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;

/**
* @author 12796
* &#064;description  针对表【announcement】的数据库操作Service实现
* &#064;createDate  2024-04-16 16:54:05
 */
@Service
public class AnnouncementServiceImpl extends ServiceImpl<AnnouncementMapper, Announcement>
    implements AnnouncementService{

    @Resource
    private RedisTemplate<String,Object> redisTemplate;

    /**
     * 获取所有的公告，先去缓存拿，拿不到去数据库拿并且放到缓存中去。
     * @return 所有的公告
     */
    @Override
    public List<Announcement> getAllAnn() {
        QueryWrapper<Announcement> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("isDelete",0);
        return this.list(queryWrapper);
    }


    /**
     * 查看某个公告
     * @param announcement 查询公告的特征值
     * @return 公告内容
     */
    @Override
    public Announcement getOneAnn(Announcement announcement) {
        if (announcement == null) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR, "数据为空");
        }
        QueryWrapper<Announcement> queryWrapper = new QueryWrapper<>(announcement);
        return this.getOne(queryWrapper);

    }
}




